[id].ts 674 B

123456789101112131415161718192021222324
  1. import axios from "axios";
  2. import type { NextApiHandler } from "next";
  3. const userUpdate: NextApiHandler = async (req, res) => {
  4. const { id } = req.query;
  5. try {
  6. const response = await axios.put(
  7. `${process.env.PRISMA_API}/user/${id}`,
  8. req.body,
  9. { headers: { "Content-Type": "application/json" } }
  10. );
  11. res.status(response.status).json(response.data);
  12. } catch (e) {
  13. if (axios.isAxiosError(e)) {
  14. res.status(e.response?.status || 500).json(e.response?.data);
  15. } else {
  16. res.status(500).json({
  17. message: "There was an error processing the request, please try again.",
  18. });
  19. }
  20. }
  21. };
  22. export default userUpdate;